/* Copyright 2009 Sony Mathew, Minneapolis MN. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
package com.xsm.muck.gwt.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;
import com.xsm.gwt.widgets.client.AxisPanel;
import com.xsm.gwt.widgets.client.CustomPanel;
import com.xsm.muck.lite.event.RonyEvent;
import com.xsm.muck.lite.event.SonyEvent;
import com.xsm.muck.lite.event.TonyEvent;

/**
 * Fires chat messages entered for 3 individuals named Sony,Rony,Tony.
 * These are (in this case) being handled by the MsgPanel including RPC reponses for them.
 * 
 * @author Sony Mathew
 */
public class ChatPanel extends CustomPanel {

    //my ioc dependencies
    public interface Context extends CustomPanel.Context {
    }

    private final Context cxt;
    
    /**
     * author Sony Mathew
     */
    public ChatPanel(Context cxt) {
        super(cxt);
        this.cxt = cxt;
    }
    
    public ChatPanel build() {
        final TextBox sonyMsgBox = new TextBox();
        Button sonyButton = new Button("Sony");
        final TextBox ronyMsgBox = new TextBox();
        Button ronyButton = new Button("Rony");
        final TextBox tonyMsgBox = new TextBox();
        Button tonyButton = new Button("Tony");
        
        AxisPanel main = new AxisPanel()
            .x(sonyMsgBox, sonyButton).q()
            .x(ronyMsgBox, ronyButton).q()
            .x(tonyMsgBox, tonyButton).q();
        
        sonyButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent e) {
                String text = sonyMsgBox.getText();
                fire(new SonyEvent(text));
            }            
        });
        
        ronyButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent e) {
                fire(new RonyEvent(ronyMsgBox.getText()));
            }            
        });

        tonyButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent e) {
                fire(new TonyEvent(tonyMsgBox.getText()));
            }            
        });
        
        add(main);
        return this;
    }
    
}
